<template>
<view class="content">
	<view class="serach">
		<input type="text" placeholder="搜索"></input>
	</view>
	<view class="main">
		<view class="tabs">
			<text v-for="(item, index) in tabs" :key="index" :class="index === tab ? 'active' : ''" @tap="select" :data-index="index">{{item}}</text>
		</view>
		<block v-if="list.length">
			<view v-for="(item, index) in list" :key="index" class="show" :data-index="index" :data-img="item.thumb_img" @tap="toDetail">
				<view class="box">
					<image :src="item.thumb_img" class="img"></image>
				</view>
				<view class="info">
					<text>{{item.goods_name}}</text>
					<view class="number">
						<text class="price">￥{{item.market_price}}</text>
						<view class="block">
							<text>库存：0</text>
							<text>销量：0</text>
							<text class="cuIcon-more lg text-gray" @tap="open" style="z-index: 15;"></text>
						</view>
					</view>
				</view>
				<view class="nav" v-if="show">
					<view class="block">
						<text class="cuIcon-upload ico"></text>
						<text>上架</text>
					</view>
					<view class="block">
						<text class="cuIcon-delete ico"></text>
						<text>删除</text>
					</view>
					<text class="cuIcon-triangledownfill ico down"></text>
				</view>
			</view>
		</block>
		<view class="noData" v-else>
			<image src="/static/remao_shop/img/noData.png"></image>
			<text>暂无数据</text>
		</view>
	</view>
</view>
</template>

<script>
import api from "../../../api";
var app = getApp();

export default {
  data() {
    return {
      user_id: '',
      tab: 0,
      tabs: ['出售中', '售罄', '仓库中', '最新'],
      show: false,
      list: []
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    wx.getStorage({
      key: 'userId',
      success: res => {
        this.setData({
          user_id: res.data
        });
      }
    });
    this.getList(3);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    getList(type) {
      wx.showLoading();
      app.globalData.request({
        url: api.default.shop_goods,
        method: 'POST',
        data: {
          store_id: 861,
          page: 1,
          type: type
        },
        success: res => {
          wx.hideLoading();
          console.log(res);
          this.setData({
            list: res.list
          });
        },
        fail: err => {
          console.log(err);
        }
      });
    },

    toDetail(e) {
      let that = this;
      console.log(e);
      let index = e.currentTarget.dataset.index;
      let img = e.currentTarget.dataset.img;
      wx.navigateTo({
        url: '../../packageA/rushdetails/rushdetails?goods_id=' + that.list[index].id + '&img=' + img + '&ismiaosha=0'
      });
    },

    select(e) {
      this.setData({
        tab: e.currentTarget.dataset.index
      });
      console.log(this.tab);

      if (this.tab == 0) {
        //店铺首页全部商品
        this.getList(3);
      } else if (this.tab == 1) {
        //售罄
        this.setData({
          list: []
        });
      } else if (this.tab == 2) {
        //仓库中全部商品
        this.getList();
      } else if (this.tab == 3) {
        //上新商品
        this.getList(2);
      }
    },

    open() {
      var that = this;
      console.log(this.show);

      if (that.show == true) {
        that.setData({
          show: false
        });
      } else {
        that.setData({
          show: true
        });
      }
    }

  }
};
</script>
<style>
@import "./commodity.css";
</style>